package com.nondo.dean.system.controller;

import com.nondo.dean.auth.common.TokenPrincipalProvider;
import com.nondo.dean.auth.common.annotation.HasUser;
import com.nondo.dean.common.annotation.ApiVersion;
import com.nondo.dean.common.web.View;
import com.nondo.dean.system.domain.Menu;
import com.nondo.dean.system.domain.MenuExample;
import com.nondo.dean.system.mapper.MenuMapper;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/{v}")
public class DemoController {

    @Autowired
    TokenPrincipalProvider principalProvider;

    @Autowired
    private MenuMapper menuMapper;

    //
    @ApiVersion(1)
    @RequestMapping(
            value = "/demo/index",
            method = {RequestMethod.POST, RequestMethod.GET}
    )
    public View<String> registerVerificationCodeEndpoint() {

        return View.ofOk(principalProvider.getTokenPrincipal().getUsername());
    }

    @ApiVersion(1)
    @RequestMapping(
            value = "/demo/index2",
            method = {RequestMethod.POST, RequestMethod.GET}
    )
    public View<String> registerVerificationCodeEndpoint2() {

        MenuExample example = new MenuExample();
        List<Menu> menus = menuMapper.selectByExampleWithRowbounds(example, new RowBounds());

        return View.ofOk(menus.size() + "ok");
    }

    @ApiVersion(1)
    @RequestMapping(
            value = "/demo/index/index3",
            method = {RequestMethod.POST, RequestMethod.GET}
    )
    public View<String> registerVerifsicationCodeEndpoint2() {

        MenuExample example = new MenuExample();
        List<Menu> menus = menuMapper.selectByExampleWithRowbounds(example, new RowBounds());

        return View.ofOk(menus.size() + "ok");
    }

}
